import Vue from 'vue'
import Router from 'vue-router'
const _import = require('./_import_' + process.env.NODE_ENV)
// in development env not use Lazy Loading,because Lazy Loading too many pages will cause webpack hot update too slow.so only in production use Lazy Loading

Vue.use(Router)

/* layout */
import Layout from '../views/layout/Layout'

/**
* icon : the icon show in the sidebar
* hidden : if `hidden:true` will not show in the sidebar
* redirect : if `redirect:noredirect` will no redirct in the levelbar
* noDropdown : if `noDropdown:true` will has no submenu
* meta : { role: ['admin'] }  will control the page role
**/
export const constantRouterMap = [
    { path: '/login', component: _import('login/index'), hidden: true },
    { path: '/authredirect', component: _import('login/authredirect'), hidden: true },
    { path: '/404', component: _import('errorPage/404'), hidden: true },
    { path: '/401', component: _import('errorPage/401'), hidden: true },
    {
      path: '/',
      component: Layout,
      redirect: '/dashboard',
      name: '首页',
      noDropdown: true,
      children: [{ path: 'dashboard', component: _import('dashboard/index'), name: '' }]
    }
]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    path: '/permission',
    component: Layout,
    redirect: '/permission/index',
    name: '权限页面',
    icon: 'lock',
    meta: { role: ['admin'] },
    noDropdown: true,
    children: [{ path: 'index', component: _import('permission/index'), name: '权限页', meta: { role: ['admin'] }}]
  },
  {
    path: '/components',
    component: Layout,
    redirect: '/components/index',
    name: '订单管理',
    noDropdown: true,
    icon: 'component',
    children: [
      { path: 'index', component: _import('components/index'), name: '订单管理' }
    ]
  },
  {
    path: '/charts',
    component: Layout,
    redirect: '/charts/index',
    name: '医生管理',
    noDropdown: true,
    icon: 'chart',
    children: [
      { path: 'index', component: _import('charts/index'), name: '医生管理' }
    ]
  },
  {
    path: '/charts',
    component: Layout,
    redirect: '/charts/index',
    name: '个代管理',
    noDropdown: true,
    icon: 'chart',
    children: [
      { path: 'index', component: _import('charts/index'), name: '个代管理' }
    ]
  },
  {
    path: '/charts',
    component: Layout,
    redirect: '/charts/index',
    name: '检测项目管理',
    noDropdown: true,
    icon: 'chart',
    children: [
      { path: 'index', component: _import('charts/index'), name: '检测项目管理' }
    ]
  },
  {
    path: '/charts',
    component: Layout,
    redirect: '/charts/index',
    name: '资讯管理',
    noDropdown: true,
    icon: 'chart',
    children: [
      { path: 'index', component: _import('charts/index'), name: '资讯管理' }
    ]
  },
  {
    path: '/charts',
    component: Layout,
    redirect: '/charts/index',
    name: '用户管理',
    noDropdown: true,
    icon: 'chart',
    children: [
      { path: 'index', component: _import('charts/index'), name: '用户管理' }
    ]
  },
  {
    path: '/charts',
    component: Layout,
    redirect: '/charts/index',
    name: '医院管理',
    noDropdown: true,
    icon: 'chart',
    children: [
      { path: 'index', component: _import('charts/index'), name: '医院管理' }
    ]
  },
  {
    path: '/charts',
    component: Layout,
    redirect: '/charts/index',
    name: '科室管理',
    noDropdown: true,
    icon: 'chart',
    children: [
      { path: 'index', component: _import('charts/index'), name: '科室管理' }
    ]
  },
  {
    path: '/message',
    component: Layout,
    redirect: '/message/index',
    name: '消息管理',
    noDropdown: true,
    icon: 'chart',
    children: [
      { path: 'index', component: _import('message/index'), name: '消息管理' }
    ]
  },
  {
    path: '/sms',
    component: Layout,
    redirect: '/sms/index',
    name: '短信验证码管理',
    noDropdown: true,
    icon: 'chart',
    children: [
      { path: 'index', component: _import('sms/index'), name: '短信验证码管理' }
    ] 
  },
  { path: '*', redirect: '/404', hidden: true }
]
